package com.zjpavt.client.page.abstractpage;

import com.zjpavt.client.page.intefacepage.MultiPage;
import lombok.extern.slf4j.Slf4j;

/**
 * 抽象的可翻页
 * @author zyc
 */
@Slf4j
public abstract class AbstractMultiPage extends AbstractBasePage implements MultiPage {
    /**
     * 内嵌页面页码 从0开始
     */
    protected int multiPageNum = 0;

    /**
     *
     */
    public AbstractMultiPage(int pageNum) {
        super(pageNum,0);
    }

    public AbstractMultiPage(int pageNum,long mRefreshPeriod) {
        super(pageNum,mRefreshPeriod);
    }


    @Override
    public abstract int getPageSize();

    /**
     * 页面增加的逻辑
     */
    @Override
    public void change2NextPage() {
        if (multiPageNum == getPageSize() - 1) {
            multiPageNum = 0;
        } else {
            multiPageNum++;
        }
        refreshPage();
    }

    @Override
    public int getMultiPageNum() {
        return multiPageNum;
    }


    @Override
    public void exitPage() {
        this.multiPageNum = 0;
    }

    @Override
    public void change2Page(int pageNum) {
        if (pageNum > getPageNum()) {
            log.error("change2Page pageNum:" + pageNum + " not exist!");
            return;
        }
        this.multiPageNum = pageNum;
        refreshPage();
    }

    @Override
    public void close() {
        exitPage();
    }
}
